package com.kingwang.training.ooad.coffeemaker.goodway.impl;

import com.kingwang.training.ooad.coffeemaker.goodway.Pollable;
import com.kingwang.training.ooad.coffeemaker.goodway.UserInterface;
import com.kingwang.training.ooad.coffeemaker.hardware.api.BrewButtonStatus;
import com.kingwang.training.ooad.coffeemaker.hardware.api.CoffeeMakerApi;
import com.kingwang.training.ooad.coffeemaker.hardware.api.IndicatorState;

/**
 * @author King
 */
public class M4UserInterface extends UserInterface implements Pollable {
    private CoffeeMakerApi coffeeMakerApi;

    public M4UserInterface(CoffeeMakerApi coffeeMakerApi) {
        this.coffeeMakerApi = coffeeMakerApi;
    }

    @Override
    public void poll() {
        BrewButtonStatus status = this.coffeeMakerApi.getBrewButtonStatus();

        if (BrewButtonStatus.PUSHED.equals(status)) {
            startBrewing();
        }
    }

    @Override
    public void done() {
        this.coffeeMakerApi.setIndecatorState(IndicatorState.ON);
    }

    @Override
    public void completeCycle() {
        this.coffeeMakerApi.setIndecatorState(IndicatorState.OFF);
    }
}
